package com.neu.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.neu.mapper.CustomerMapper;
import com.neu.mapper.SalesmanMapper;
import com.neu.po.Customer;
import com.neu.po.CustomerExample;
import com.neu.po.Salesman;
import com.neu.po.SalesmanExample;

@Service
public class SalesmanServiceImpl implements SalesmanService {
	@Autowired
	private SalesmanMapper salesmanMapper;
	@Autowired
	private CustomerMapper customerMapper;
	
	@Override
	public PageInfo<Salesman> getPaged(int pageNum,int pageSize,String keyword) {
		SalesmanExample example = new SalesmanExample();
		
		PageHelper.startPage(pageNum, pageSize);
		
		List<Salesman> list = salesmanMapper.selectByExample(example);
		
		PageInfo<Salesman> pageinfo = new PageInfo<>(list);
		
		return pageinfo;
	}

	@Override
	public List<Salesman> getAll() {
		SalesmanExample example = new SalesmanExample();
		return salesmanMapper.selectByExample(example);
	}

	@Override
	public int update(Salesman salesman) {

		return salesmanMapper.updateByPrimaryKey(salesman);
	}

	@Override
	public int insert(Salesman salesman) {

		return salesmanMapper.insertSelective(salesman);
	}

	@Override
	public List<Customer> getAllCustomer() {
		CustomerExample example = new CustomerExample();
		return customerMapper.selectByExample(example);
	}

	@Override
	public int delete(int id) {
		
		return salesmanMapper.deleteByPrimaryKey(id);
	}

}
